// Copyright (c) 2010, Anthony Cassidy
// All rights reserved.
// 
// Redistribution and use in source and binary forms, with or without modification, are 
// permitted provided that the following conditions are met:
// 
//     * Redistributions of source code must retain the above copyright notice, this list 
//         of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright notice, this 
//         list of conditions and the following disclaimer in the documentation and/or 
//         other materials provided with the distribution.
//     * Neither the name of the AntsAdventureGameCreator nor the names of its contributors 
//         may be used to endorse or promote products derived from this software without 
//         specific prior written permission.
// 
// 
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
// THE POSSIBILITY OF SUCH DAMAGE.
#include "XStdafx.h"
#include "ChoicesHelper.h"
#include "Choices.h"
#include "XChoicesDialog.h"

ChoicesHelper::ChoicesHelper(Choices& choices)
: m_orig(choices)
{
}

void ChoicesHelper::Add(QString file, int lineNumber, int i, QString displayString, bool isVisible, bool isOneShot)
{
    // in debug, I decided to add *all* the options, so you don't have to play thru. 
    bool isOkToAdd = isVisible;
#ifdef _DEBUG
    isOkToAdd = true;
#endif

    if(isOkToAdd)
    {
        QString comment = "";
        if(file.length() && lineNumber>-1)
        {
            QString line;
            bool isOk = XChoicesDialog::TryReadLine(file,lineNumber,&line);
            if(isOk)
            {
                if(line.contains("//"))
                {
                    comment = line.remove(0,line.lastIndexOf("//")+2);
                    comment = comment.trimmed();
                }
            }
        }

        m_orig.m_displayStrings.push_back( displayString );
        m_orig.m_indices.push_back(i);
        m_orig.m_isVisible.push_back(isVisible);
        m_orig.m_comments.push_back(comment);
        m_orig.m_files.push_back(file);
        m_orig.m_lines.push_back(lineNumber);
        m_orig.m_isOneShot.push_back(isOneShot);
    }
}

void ChoicesHelper::Add(QString file, int line, int i, QString displayString, ...)
{
    va_list iterator;
    va_start(iterator, displayString);
    bool isToBeShown = va_arg(iterator, int);

    Add(file,line,i,displayString,isToBeShown, false);
}

void ChoicesHelper::Add(int i, QString displayString, ...)
{
    va_list iterator;
    va_start(iterator, displayString);

    bool isToBeShown = va_arg(iterator, int);

    va_end(iterator);

    Add("",-1,i,displayString,isToBeShown);
}
